package com.njtoyo.taxi.admin.library.common.util;

import cn.hutool.core.date.DateUtil;
import com.njtoyo.taxi.admin.library.common.Enum;
import com.njtoyo.taxi.admin.mapper.master.enums.RankListTimeRangeType;
import com.njtoyo.taxi.admin.mapper.secondary.enums.CacheDriverWorkingType;
import com.njtoyo.taxi.admin.rest.presenter.data.data_analysis.SearchTimeTypePresenter;
import com.njtoyo.taxi.admin.rest.wrapper.data.rank.CacheDriverWorkingDto;

import java.util.Date;

public class SearchTimeType {

    public static SearchTimeTypePresenter getStartAndEndByType(Enum.DateGroupType type) {
        SearchTimeTypePresenter res = new SearchTimeTypePresenter();
        res.setEndTime(DateUtil.date());

        switch (type) {
            case day:
                // 今日
                res.setStartTime(DateUtil.beginOfDay(DateUtil.date()));
                break;
            case week:
                // 本周
                res.setStartTime(DateUtil.beginOfWeek(DateUtil.date()));
                break;
            case month:
                // 本月
                res.setStartTime(DateUtil.beginOfMonth(DateUtil.date()));
                break;
        }

        return res;
    }

    public static CacheDriverWorkingDto convertDriverWorkingTimeType(RankListTimeRangeType timeType, Date startTime, Date endTime) {
        CacheDriverWorkingDto res = new CacheDriverWorkingDto();

        res.setStartTime(startTime);

        // 类型
        switch (timeType) {
            case day:
                res.setType(CacheDriverWorkingType.day);
                res.setEndTime(DateUtil.beginOfDay(DateUtil.endOfDay(startTime)));
                break;
            case week:
                res.setType(CacheDriverWorkingType.week);
                res.setEndTime(DateUtil.beginOfDay(DateUtil.endOfWeek(startTime)));
                break;
            default:
            case month:
                res.setType(CacheDriverWorkingType.month);
                res.setEndTime(DateUtil.beginOfDay(DateUtil.endOfMonth(startTime)));
                break;
            case customize:
                res.setType(CacheDriverWorkingType.month);
                res.setEndTime(DateUtil.beginOfDay(endTime));
                break;
        }

        return res;
    }
}
